package com.kun.ack;

import com.kun.util.ResourceUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.Scanner;

/**
 * 消息生产者，用于测试消费者手工应答和重回队列
 */
public class AckProducer {

    private final static String QUEUE_NAME = "TEST_ACK_QUEUE";

    public static void main(String[] args) throws Exception {

        Scanner scanner = new Scanner(System.in);

        ConnectionFactory factory = new ConnectionFactory();
        factory.setUri(ResourceUtil.getKey("rabbitmq.uri"));

        // 建立连接
        Connection conn = factory.newConnection();
        // 创建消息通道
        Channel channel = conn.createChannel();

        // 声明队列（默认交换机AMQP default，Direct）
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        //String msg = "test ack message ";

        // 手动输入,发送消息
        while (scanner.hasNext()){
            channel.basicPublish("", QUEUE_NAME, null, scanner.nextLine().getBytes());
        }


        channel.close();
        conn.close();
    }
}

